home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 32 / cadence.zip / VOL1NO4.ZIP / SPSINP.LSP < prev    next >
Text File  |  1986-09-04  |  4KB  |  103 lines

  1. ; =================================================================
  2. ;    SPSINP  Spreadsheet Interface Macro.     by Bill Kramer  1986
  3. ;
  4. ;    Read a text file character by character, building a set of
  5. ;    columns from the data.  Numeric data is expected to be found
  6. ;    in the comma delimited format.
  7. ;
  8. ;    Variables Used
  9. ;
  10. ;       COLMS      List  (Real)      Location of decimal point in
  11. ;                                    column
  12. ;       YY         Real              Current row location
  13. ;       FH         File Pointer      Input file handle
  14. ;       FNAM       String            File name
  15. ;       CH         Integer           Character read in from file
  16. ;       TH         Real              Text height
  17. ;       TV         Real              Text vertical spacing distance
  18. ;       FLAG       Integer           Header/Trailer flip-flop
  19. ;       NN         Integer           Current column number
  20. ;       NX         Integer           Max column number
  21. ;       HD         String            Header (before decimal)
  22. ;       TR         String            Trailer (after decimal)
  23. ;       TX         Real              X coordinate for text output
  24. ; ====================================================================
  25. ;  Function SPSTXT, outputs text strings HD and TR.
  26. ;
  27. (defun spstxt ()
  28.    (setq flag 1) ; Reset Flip/Flop flag for definition of header/trailer.
  29.    (setq mmm (* th 0.25)) ; Space between decimal and header number.
  30.    (setq tx (- (nth nn colms) mmm)) 
  31.    (command   ; Right justify text to just left of decimal location.
  32.       "text" "r" (list tx yy) th 0.0
  33.       hd
  34.    )
  35.    (setq tx (nth nn colms))
  36.    (command
  37.       "text" (list tx yy) th 0.0
  38.       (strcat "." tr)
  39.    )
  40.    (setq hd "") (setq tr "")(setq nn (1+ nn))
  41. )
  42. ; ---------------------------------------------
  43. ;  Function SPSINP (AutoCAD Macro)
  44. ; ---------------------------------------------
  45. (defun c:spsinp ()
  46.    (setvar "CMDECHO" 0)   ; Turn off command echos
  47.    (setq colms (list 0.0)) ; Initialize list of column settings.
  48.    (setq hd "") (setq tr "") ; Initialize character string variables.
  49.    (setq nx (getint "\nNumber of Columns:"))
  50.    (if (not (null nx))  ; Option: use BOUNDP 'NX
  51.        (progn
  52.           (prompt "\nShow the Column X locations:")
  53.           (repeat nx
  54.             (setq colms (cons (car (getpoint)) colms))
  55.           )
  56.           (setq colms (cdr (reverse colms)))
  57.           (setq yy (cadr (getpoint "\nStarting Y Coordinate:")))
  58.           (setq th (getreal "\nText Height:"))
  59.           (setq tv (getreal "\nVertical Spacing:"))
  60.           (setq fnam (getstring "\nName of File:"))
  61.           (setq fh (open fnam "r"))
  62.           (if (null fh)
  63.               (prompt "\nFile not found")
  64.               (progn   ; Else <file was found!>
  65.                 (setq ch 1)(setq nn 0)(setq flag 1)
  66.                 (while (not (null fh))   ; Option: use BOUNDP 'FH
  67.                   (setq ch (read-char fh))
  68.                   (cond
  69.                     ((= ch 44)   ; Comma ","
  70.                      (spstxt) ; End of column data, output text.
  71.                      (if (= nn nx)
  72.                           (progn
  73.                              (setq nn 0)
  74.                              (setq yy (- yy tv))
  75.                           )
  76.                      )
  77.                     )
  78.                     ((= ch 46) ; Period "."
  79.                      (setq flag 2) ; Remaining characters in trailer.
  80.                     )
  81.                     ((= ch 10) ; Return, end of line.
  82.                      (spstxt) ; End of column data, output text.
  83.                      (setq yy (- yy tv)) ; Prepare for next line.
  84.                      (setq nn 0)
  85.                     )
  86.                     ((= ch nil) ; End of file read?
  87.                      (close fh)
  88.                      (setq fh nil)
  89.                     )
  90.                     ((/= ch 32) ; Not a space, add to string.
  91.                      (if (= flag 1) ; Add to header or trailer?
  92.                          (setq hd (strcat hd (chr ch)))
  93.                          (setq tr (strcat tr (chr ch)))
  94.                      )
  95.                     )
  96.                   ) ; End of Conditional Test of CH value.
  97.                 ) ; End of While Loop
  98.               ) ; End of PROGN <Else file was found>
  99.           ) ; End of IF test for file not found.
  100.        ) ; End of 1st PROGN
  101.    ) ; End of IF test for column numbers
  102. )
  103.